/**
 * 有序的二分查找，返回-1或存在的数组下标。不使用递归实现。
 * @param target
 * @param arr
 * @returns {*}
 */
export function binarySearch(arr,success:(current)=>boolean) {
    let start   = 0;
    let end     = arr.length-1;
    let last
    while (start<=end){
        var mid = parseInt(start+(end-start)/2 + "");
        if(success(arr[mid])){
            return mid;
        }else if(arr[mid]){
            start = mid+1;
        }else{
            end  = mid-1;
        }
    }
    return -1;
}